home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / totsrc.zip / TOTMSG.PAS < prev    next >
Pascal/Delphi Source File  |  1991-02-11  |  13KB  |  519 lines

  1. {               Copyright 1991 TechnoJock Software, Inc.               }
  2. {                          All Rights Reserved                         }
  3. {                         Restricted by License                        }
  4.  
  5. {                             Build # 1.00                             }
  6.  
  7. Unit totMSG;
  8. {$I TOTFLAGS.INC}
  9.  
  10. {
  11.  Development Notes:
  12.  
  13. }
  14.  
  15. INTERFACE
  16.  
  17. uses DOS, CRT, totSYS, totINPUT, totFAST, totIO1, totWIN, totSTR;
  18.  
  19. CONST
  20.    MaxButtons = 10;
  21.  
  22. TYPE
  23. MsgNodePtr = ^MsgNode;
  24. MsgNode = record
  25.    Txt : pointer;
  26.    Next: MsgNodePtr;
  27. end; {MsgNode}
  28.  
  29. ButtonDetails = record
  30.   Txt: stringbut;
  31.   Code: tAction;
  32.   HK: word;
  33.   Len : byte;
  34. end; {ButtonDetails}
  35.  
  36. pBaseMessageOBJ = ^BaseMessageOBJ;
  37. BaseMessageOBJ = object
  38.    vTxtStack: MsgNodePtr;
  39.    vManager: WinFormOBJ;
  40.    vTotLines: byte;
  41.    vStyle: byte;
  42.    vWidth : byte;
  43.    vButtonDepth: byte;
  44.    vMinWidth: byte;
  45.    vTotButtons: byte;
  46.    vButtons: array[1..MaxButtons] of pItemIOOBJ;
  47.    {methods ...}
  48.    constructor Init(Style:byte;Tit:string);
  49.    procedure   AddLine(Str:string);
  50.    function    MsgTxt(LineNo:byte): string;
  51.    function    WinForm: WinFormPtr;
  52.    procedure   AssignButton(var Button:ItemIOOBJ);
  53.    procedure   CalcSize;
  54.    function    Show: tAction;
  55.    destructor  Done;                                     VIRTUAL;
  56. end; {BaseMessageOBJ}
  57.  
  58. pMessageOBJ = ^MessageOBJ;
  59. MessageOBJ = object (BaseMessageOBJ)
  60.    vButtonText : stringbut;
  61.    vButtonHK: word;
  62.    {methods ...}
  63.    constructor Init(Style:byte;Tit:string);
  64.    procedure   SetOption(Str:string;Hotkey:word);
  65.    procedure   Show;
  66.    destructor  Done;                                     VIRTUAL;
  67. end; {MessageOBJ}
  68.  
  69. pButtonMessageOBJ = ^ButtonMessageOBJ;
  70. ButtonMessageOBJ = object (MessageOBJ)
  71.    {methods ...}
  72.    constructor Init(Style:byte;Tit:string);
  73.    procedure   Show;
  74.    destructor  Done;                                     VIRTUAL;
  75. end; {ButtonMessageOBJ}
  76.  
  77. pPromptOBJ = ^PromptOBJ;
  78. PromptOBJ = object (BaseMessageOBJ)
  79.    vButtonInfo : array [1..3] of ButtonDetails;
  80.    vTotPrompts: byte;
  81.    {methods ...}
  82.    constructor Init(Style:byte;Tit:string);
  83.    procedure   SetOption(ID:byte; Str:stringbut;HotKey:word; Act:tAction);
  84.    procedure   LoadButtonRecord(Rec:byte;Str:stringbut;Hotkey:word;Act:tAction);
  85.    function    Show: tAction;
  86.    destructor  Done;                                     VIRTUAL;
  87. end; {PromptOBJ}
  88.  
  89. pButtonPromptOBJ = ^ButtonPromptOBJ;
  90. ButtonPromptOBJ = object (promptOBJ)
  91.    {methods ...}
  92.    constructor Init(Style:byte;Tit:string);
  93.    function    Show: tAction;
  94.    destructor  Done;                                     VIRTUAL;
  95. end; {ButtonPromptOBJ}
  96.  
  97. procedure MsgInit;
  98.  
  99. IMPLEMENTATION
  100.  
  101. {|||||||||||||||||||||||||||||||||||||||||||||||||||}
  102. {                                                   }
  103. {    B a s e M e s s a g e O B J   M E T H O D S    }
  104. {                                                   }
  105. {|||||||||||||||||||||||||||||||||||||||||||||||||||}
  106. constructor BaseMessageOBJ.Init(Style:byte;Tit:string);
  107. {}
  108. begin
  109.    vTotLines := 0;
  110.    vStyle := Style;
  111.    vTxtStack := Nil;
  112.    vWidth := length(Tit) + 10;
  113.    vMinWidth := 10;
  114.    vTotButtons := 0;
  115.    vButtonDepth := 1;
  116.    with vManager do
  117.    begin
  118.       Init;
  119.       Win^.SetTitle(Tit);
  120.    end; 
  121. end; {BaseMessageOBJ.Init}
  122.  
  123. procedure BaseMessageOBJ.AddLine(Str:string);
  124. {}          
  125. var L : byte;
  126.     Temp: MsgNodePtr;
  127. begin
  128.    L := succ(length(Str));
  129.    if vTxtStack = Nil then
  130.    begin
  131.       getmem(vTxtStack,sizeof(vTxtStack^));
  132.       vTxtStack^.Next := nil;
  133.       if Str <> '' then
  134.       begin
  135.          getmem(vTxtStack^.Txt,L);
  136.          move(Str[0],vTxtStack^.Txt^,L);
  137.       end
  138.       else
  139.          vTxtStack^.Txt := nil;
  140.    end
  141.    else
  142.    begin
  143.       Temp := vTxtStack;
  144.       while Temp^.Next <> nil do
  145.          Temp := Temp^.Next;
  146.       getmem(Temp^.Next,sizeof(Temp^.Next^));
  147.       Temp := Temp^.Next;
  148.       Temp^.Next := nil;
  149.       if Str <> '' then
  150.       begin
  151.          getmem(Temp^.Txt,L);
  152.          move(Str[0],Temp^.Txt^,L);
  153.       end
  154.       else
  155.          Temp^.Txt := nil;
  156.    end;
  157.    inc(vTotLines);
  158. end; {BaseMessageOBJ.AddLine}
  159.  
  160. function BaseMessageOBJ.MsgTxt(LineNo:byte): string;
  161. {}
  162. var
  163.    Temp: MsgNodePtr;
  164.    I:integer;
  165.    L : byte;
  166.    Str: string;
  167. begin
  168.    Temp := vTxtStack;
  169.    for I := 2 to LineNo do
  170.       if Temp <> nil then
  171.          Temp := Temp^.Next;
  172.    if (Temp <> Nil) and (Temp^.Txt <> nil) then
  173.    begin
  174.       move(Temp^.Txt^,L,1);
  175.       move(Temp^.Txt^,Str[0],succ(L));
  176.    end
  177.    else
  178.       Str := '';
  179.    MsgTxt := Str;
  180. end; {BaseMessageOBJ.MsgTxt}
  181.  
  182. procedure BaseMessageOBJ.AssignButton(var Button:ItemIOOBJ);
  183. {}
  184. begin
  185.    if vTotButtons < MaxButtons then
  186.    begin
  187.       inc(vTotButtons);
  188.       vButtons[vTotButtons] := @Button
  189.    end;
  190. end; {BaseMessageOBJ.AssignButton}
  191.  
  192. procedure BaseMessageOBJ.CalcSize;
  193. {}
  194. var
  195.    X1,Y1,X2,Y2: shortint;
  196.    Height: byte;
  197.    I : integer;
  198.    Str : string;
  199. begin
  200.    for I := 1 to vTotLines do
  201.    begin
  202.       Str := MsgTxt(I);
  203.       if length(Str) > vWidth then
  204.          vWidth := length(Str);
  205.    end;
  206.    if vWidth < vMinWidth then
  207.       vWidth := vMinWidth
  208.    else if vWidth > 80 then
  209.       vWidth := 76;
  210.    if (vStyle <> 0) then
  211.       vWidth := vWidth + 2;
  212.    X1 := (Monitor^.Width - vWidth) div 2;
  213.    X2 := X1 + pred(vWidth);
  214.    case vStyle of
  215.       0: Height := vTotLines;
  216.       6: Height := vTotLines + 3;
  217.       else Height := vTotLines + 2;
  218.    end; {case}
  219.    inc(Height,succ(vButtondepth));
  220.    Y1 := (Monitor^.Depth - Height) div 2;
  221.    Y2 := Y1 + pred(Height);
  222.    vManager.Win^.SetSize(X1,Y1,X2,Y2,vStyle);
  223. end; {BaseMessageOBJ.CalcSize}
  224.  
  225. function BaseMessageOBJ.Show:tAction;
  226. {}
  227. var
  228.    I : integer;
  229.    S : string;
  230. begin
  231.    for I := 1 to vTotButtons do
  232.       vManager.AddItem(vButtons[I]^);
  233.    vManager.Draw;
  234.    for I := 1 to vTotLines do
  235.    begin
  236.       S := MsgTxt(I);
  237.       if S <> '' then
  238.          case S[1] of
  239.             '^': begin
  240.                delete(S,1,1);
  241.                Screen.WriteCenter(I,vManager.Win^.GetBodyAttr,S);
  242.             end;
  243.             '"': begin
  244.                delete(S,1,1);
  245.                Screen.WriteRight(vWidth - 2*ord(vStyle<>0),I,
  246.                                  vManager.Win^.GetBodyAttr,S);
  247.             end;
  248.             else   Screen.WritePlain(1,I,S);
  249.          end;  {case}
  250.    end;
  251.    Show := vManager.Go;
  252.    delay(100);
  253.    vManager.Done;
  254. end; {BaseMessageOBJ.Show}
  255.  
  256. function BaseMessageOBJ.WinForm: WinFormPtr;
  257. {}
  258. begin
  259.    WinForm := @vManager;
  260. end; {BaseMessageOBJ.WinForm}
  261.  
  262. destructor BaseMessageOBJ.Done;
  263. {}
  264. var
  265.   L: byte;
  266.   TempA,TempB: MsgNodePtr;
  267.   I : integer;
  268. begin
  269.    TempA := vTxtStack;
  270.    while TempA <> nil do
  271.    begin
  272.        TempB := TempA;
  273.        TempA := TempB^.Next;
  274.        if TempB^.Txt <> Nil then
  275.        begin
  276.           move(TempB^.Txt^,L,1);
  277.           freemem(TempB^.Txt,succ(L)); {dispose of text}
  278.        end;
  279.        freemem(TempB,sizeof(tempB^));
  280.    end;
  281. end; {BaseMessageOBJ.Done}
  282. {||||||||||||||||||||||||||||||||||||||||||||}
  283. {                                            }
  284. {     M e s s a g e O B J   M E T H O D S    }
  285. {                                            }
  286. {||||||||||||||||||||||||||||||||||||||||||||}
  287. constructor MessageOBJ.Init(Style:byte;Tit:string);
  288. {}
  289. begin
  290.    BaseMessageOBJ.Init(Style,Tit);
  291.    vButtonText := '  ~O~K  ';
  292.    vButtonHK :=  79;
  293. end; {MessageOBJ.Init}
  294.    
  295. procedure MessageOBJ.SetOption(Str:string;HotKey: word);
  296. {}
  297. begin
  298.    vButtonText := Str;
  299.    vButtonHK := HotKey;
  300. end; {MessageOBJ.SetOptionText}
  301.  
  302. procedure MessageOBJ.Show;
  303. {}
  304. var
  305.    OK: Strip3dIOOBJ;
  306.    EscHK: HotKeyIOOBJ;
  307.    HK: HotKeyIOOBJ;
  308.    TempAct: tAction;
  309. begin
  310.    vMinWidth := length(vButtonText) + 4;
  311.    CalcSize;
  312.    OK.Init((vWidth - length(vButtonText))div 2 ,succ(vTotLines),vButtonText,Finished);
  313.    EscHK.Init(27,Finished);
  314.    OK.SetHotkey(vButtonHK);
  315.    AssignButton(OK);
  316.    AssignButton(EscHK);
  317.    TempAct := BaseMessageOBJ.Show;
  318.    OK.Done;
  319.    EscHK.Done;
  320. end; {MessageOBJ.Show}
  321.  
  322. destructor MessageOBJ.Done;
  323. {}
  324. begin
  325.    BaseMessageOBJ.Done
  326. end; {MessageOBJ.Done}
  327. {||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  328. {                                                        }
  329. {     B u t t o n M e s s a g e O B J   M E T H O D S    }
  330. {                                                        }
  331. {||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  332. constructor ButtonMessageOBJ.Init(Style:byte;Tit:string);
  333. {}
  334. begin
  335.    MessageOBJ.Init(Style,Tit);
  336.    vButtonDepth := 2;
  337. end; {ButtonMessageOBJ.Init}
  338.    
  339. procedure ButtonMessageOBJ.Show;
  340. {}
  341. var
  342.    OK: ButtonIOOBJ;
  343.    EscHK: HotKeyIOOBJ;
  344.    TempAct: tAction;
  345. begin
  346.    CalcSize;
  347.    OK.Init((vWidth - length(vButtonText))div 2 ,succ(vTotLines),
  348.              vButtonText,Finished);
  349.    OK.SetHotkey(vButtonHK);
  350.    EscHK.Init(27,Finished);
  351.    AssignButton(OK);
  352.    AssignButton(EscHK);
  353.    TempAct := BaseMessageOBJ.Show;
  354.    EscHk.Done;
  355. end; {ButtonMessageOBJ.Show}
  356.  
  357. destructor ButtonMessageOBJ.Done;
  358. {}
  359. begin
  360.    MessageOBJ.Done
  361. end; {ButtonMessageOBJ.Done}
  362. {||||||||||||||||||||||||||||||||||||||||||}
  363. {                                          }
  364. {     P r o m p t O B J   M E T H O D S    }
  365. {                                          }
  366. {||||||||||||||||||||||||||||||||||||||||||}
  367. constructor PromptOBJ.Init(Style:byte;Tit:string);
  368. {}
  369. begin
  370.    BaseMessageOBJ.Init(Style,Tit);
  371.    SetOption(1,'  ~O~K  ',79,Finished);
  372.    SetOption(2,' ~C~ancel ',67,Escaped);
  373.    vTotPrompts := 2;
  374. end; {PromptOBJ.Init}
  375.    
  376. procedure PromptOBJ.LoadButtonRecord(Rec:byte;Str:stringbut;
  377.                                      Hotkey:word;Act:tAction);
  378. {}
  379. begin
  380.    with vButtonInfo[Rec] do
  381.    begin
  382.       Txt := Str;
  383.       Code := Act;
  384.       Len := length(Strip('A','~',Str));
  385.       HK := Hotkey;
  386.    end;
  387. end; {PromptOBJ.LoadButtonRecord}
  388.  
  389. procedure PromptOBJ.SetOption(ID:byte; Str:stringbut;HotKey:word; Act:tAction);
  390. {}
  391. begin
  392.    if ID in [1..3] then
  393.       LoadButtonRecord(ID,Str,HotKey,Act);
  394.    if ID = 3 then
  395.       vTotPrompts := 3;
  396. end; {PromptOBJ.SetOptions}
  397.  
  398. function PromptOBJ.Show: tAction;
  399. {}
  400. type 
  401.    But = record
  402.       Button: Strip3dIOOBJ;
  403.       XCoord: byte;
  404.    end;
  405. var
  406.    MoveKeys: ControlKeysIOOBJ;
  407.    Buttons : array[1..3] of But;
  408.    Temp: byte;
  409.    I : integer;
  410. begin
  411.    Temp := 0;
  412.    for I := 1 to vTotprompts do
  413.      inc(Temp,vButtonInfo[I].Len);
  414.    vMinWidth := Temp + succ(vTotPrompts);
  415.    CalcSize;
  416.    Temp := (vWidth - Temp) div succ(vTotPrompts);
  417.    Buttons[1].XCoord := Temp;
  418.    for I := 2 to vTotPrompts do
  419.       Buttons[I].XCoord := Temp + Buttons[pred(I)].XCoord + vButtonInfo[pred(I)].Len;
  420.    for I := 1 to vTotPrompts do
  421.    begin
  422.       with Buttons[I] do
  423.       begin
  424.         Button.Init(XCoord,succ(vTotLines),vButtonInfo[I].Txt,vButtonInfo[I].Code);
  425.         if vButtonInfo[I].HK <> 0 then
  426.           Button.Sethotkey(vButtonInfo[I].HK);
  427.        AssignButton(Button);
  428.       end; 
  429.    end;
  430.    MoveKeys.Init;
  431.    AssignButton(MoveKeys);
  432.    Show := BaseMessageOBJ.Show;
  433.    for I := 1 to vTotPrompts do
  434.       Buttons[I].Button.Done;
  435.    MoveKeys.Done;
  436. end; {PromptOBJ.Show}
  437.  
  438. destructor PromptOBJ.Done; 
  439. {}
  440. begin
  441.     BaseMessageOBJ.Done;
  442. end; {PromptOBJ.Done}
  443. {||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  444. {                                                      }
  445. {     B u t t o n P r o m p t O B J   M E T H O D S    }
  446. {                                                      }
  447. {||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  448. constructor ButtonPromptOBJ.Init(Style:byte;Tit:string);
  449. {}
  450. begin
  451.    PromptOBJ.Init(Style,Tit);
  452.    vButtonDepth := 2;
  453. end; {ButtonPromptOBJ.Init}
  454.    
  455. function ButtonPromptOBJ.Show: tAction;
  456. {}
  457. type 
  458.    But = record
  459.       Button: ButtonIOOBJ;
  460.       XCoord: byte;
  461.    end;
  462. var
  463.    MoveKeys: ControlKeysIOOBJ;
  464.    Buttons : array[1..3] of But;
  465.    Temp: byte;
  466.    I : integer;
  467. begin
  468.    Temp := 0;
  469.    for I := 1 to vTotprompts do
  470.      inc(Temp,vButtonInfo[I].Len+2);
  471.    vMinWidth := Temp + succ(vTotPrompts);
  472.    CalcSize;
  473.    Temp := (vWidth - Temp) div succ(vTotPrompts);
  474.    Buttons[1].XCoord := Temp;
  475.    for I := 2 to vTotPrompts do
  476.       Buttons[I].XCoord := Temp + Buttons[pred(I)].XCoord + vButtonInfo[pred(I)].Len + 2;
  477.    for I := 1 to vTotPrompts do
  478.    begin
  479.       with Buttons[I] do
  480.       begin
  481.         Button.Init(XCoord,succ(vTotLines),vButtonInfo[I].Txt,vButtonInfo[I].Code);
  482.         if vButtonInfo[I].HK <> 0 then
  483.           Button.Sethotkey(vButtonInfo[I].HK);
  484.        AssignButton(Button);
  485.       end; 
  486.    end;
  487.    MoveKeys.Init;
  488.    AssignButton(MoveKeys);
  489.    Show := BaseMessageOBJ.Show;
  490.    for I := 1 to vTotPrompts do
  491.       Buttons[I].Button.Done;
  492.    MoveKeys.Done;
  493. end; {ButtonPromptOBJ.Show}
  494.  
  495. destructor ButtonPromptOBJ.Done;
  496. {}
  497. begin
  498.    PromptOBJ.Done
  499. end; {ButtonPromptOBJ.Done}
  500. {|||||||||||||||||||||||||||||||||||||||||||||||}
  501. {                                               }
  502. {     U N I T   I N I T I A L I Z A T I O N     }
  503. {                                               }
  504. {|||||||||||||||||||||||||||||||||||||||||||||||}
  505. procedure MsgInit;
  506. {initilizes objects and global variables}
  507. begin
  508. end;
  509.  
  510. {end of unit - add intialization routines below}
  511. {$IFNDEF OVERLAY}
  512. begin
  513.    MsgInit;
  514. {$ENDIF}
  515. end.
  516.  
  517.  
  518.  
  519.